package com.jsyl.web.config.filter;

import java.io.IOException;

import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.filter.OncePerRequestFilter;


/**
 * 服务上下文管理
 * @author binbinccut@163.com
 *
 */
public class PlatformContextFilter extends OncePerRequestFilter {

	/**
	 * 默认皮肤路径
	 */
	private String defaultSkin;

	public void setDefaultSkin(String defaultSkin) {
		this.defaultSkin = defaultSkin;
	}

	@Override
	protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
			throws ServletException, IOException {

		// 获取系统根路径
		String ctx = request.getServletContext().getContextPath();
		String skinPath = ctx + "/" + this.defaultSkin;

		// 生成CSS路径
		String cssPath = skinPath + "/css";

		// 生成js路径
		String jsPath = skinPath + "/js";

		// 生成images路径
		String imagesPath = skinPath + "/images";

		// 生成js插件路径
		String pluginPath = skinPath + "/plugin";

		// 生成业务js路径
		String templatesPath = skinPath + "/templates";
		
		request.setAttribute("ctx", ctx);
		request.setAttribute("cssPath", cssPath);
		request.setAttribute("jsPath", jsPath);
		request.setAttribute("imgPath", imagesPath);
		request.setAttribute("plugPath", pluginPath);
		request.setAttribute("tmpJsPath", templatesPath);

		filterChain.doFilter(request, response);
	}

}
